package diploma.kisel.modelas.service;

import java.util.ArrayList;
import java.util.List;

import diploma.kisel.modelas.domain.Workplace;
import diploma.kisel.modelas.repository.WorkplaceRepositoryImpl;
import diploma.kisel.modelas.repository.api.WorkplaceRepository;
import diploma.kisel.modelas.service.api.WorkplaceService;

public class WorkplaceServiceImpl implements WorkplaceService{
	
	WorkplaceRepository workplaceRepository = new WorkplaceRepositoryImpl();

	@Override
	public List<Workplace> findAll() {
		return workplaceRepository.findAll();
	}

	@Override
	public Workplace findById(int id) {
		if (id>=0)
			return workplaceRepository.findById(id);
		else
			return null;
	}

	@Override
	public Workplace save(Workplace workplace) {
		if (workplace!=null) {
			if (workplace.getId()!=null) 
				workplaceRepository.update(workplace);
			else
				workplaceRepository.save(workplace);
		}
		return null;
	}

	@Override
	public void remove(Workplace workplace) {
		if (workplace!=null && workplace.getId()!=null)
			workplaceRepository.remove(workplace);
		
	}

	@Override
	public void remove(int id) {
		Workplace workplace = findById(id);
		remove(workplace);		
	}

}
